/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import POJO.XuatChieuPoJo;
import java.sql.ResultSet;

/**
 *
 * @author tran quoc thinh
 */
public class XuatChieuDAO {
    public static ResultSet LayBangXuatChieu()
    {
       MySQLDataAccessHelper helper =new MySQLDataAccessHelper();
       helper.Open();
       String sql="select * from xuatchieu";
       ResultSet rs=helper.excecuteQuery(sql);       
       return rs;       
    }
    public static ResultSet LayBangXuatChieuTheoMaPhim(String MPhim)
    {
       MySQLDataAccessHelper helper =new MySQLDataAccessHelper();
       helper.Open();
       String sql=String.format("select * from xuatchieu where MaPhim='%s'",MPhim);
       ResultSet rs=helper.excecuteQuery(sql);       
       return rs;       
    }
    public static ResultSet LayBangXuatChieuTheoMaPhong(String MPhong)
    {
       MySQLDataAccessHelper helper =new MySQLDataAccessHelper();
       helper.Open();
       String sql=String.format("select * from xuatchieu where MaPhong='%s'",MPhong);
       ResultSet rs=helper.excecuteQuery(sql);       
       return rs;       
    } 
     public static ResultSet LayBangXuatChieuTheoMaPhimVaMaPhong(String MPhong,String MPhim)
    {
       MySQLDataAccessHelper helper =new MySQLDataAccessHelper();
       helper.Open();
       String sql=String.format("select * from xuatchieu where MaPhong='%s' and MaPhim='%s'",MPhong,MPhim);
       ResultSet rs=helper.excecuteQuery(sql);       
       return rs;       
    } 
     
    public static ResultSet LayBangXuatChieuTheoMaPhimHoa(String MPhim)
    {
       try
        {
            ResultSet rs;
            MySQLDataAccessHelper dahp = new MySQLDataAccessHelper();
            dahp.Open();
            String sql = "select * from xuatchieu where maphim = '"+MPhim+"'";
            rs = dahp.excecuteQuery(sql);        
            return rs;
        }
        catch(Exception ex)
        {
            System.out.println(ex.getMessage());            
        }
        return null;    
    }
     public static int ThemXC(XuatChieuPoJo p)
    {
        MySQLDataAccessHelper helper=new MySQLDataAccessHelper();
        helper.Open();
        String sql=String.format("INSERT INTO xuatchieu (NgayChieu,GioChieu,MaPhim,MaPhong)"
                + "VALUES('%s','%s','%s','%s')",p.getNgayChieu(),p.getGioChieu(),p.getMaPhim(),p.getMaPhong());
        int n=helper.excecuteUpdate(sql);
        helper.Close();
        return n;
    }
     public static int SuaPhim(XuatChieuPoJo p)
    {
         MySQLDataAccessHelper helper=new MySQLDataAccessHelper();
         helper.Open();
         String sql=String.format("UPDATE xuatchieu SET NgayChieu='%s',GioChieu='%s',MaPhim='%s',MaPhong='%s' WHERE MaXC='%d'",p.getNgayChieu(),p.getGioChieu(),p.getMaPhim(),p.getMaPhong(),p.getMaXC());
         int n=helper.excecuteUpdate(sql);
         helper.Close();
         return n;
    }

    public static int XoaXuatChieu(int xc){
        
         MySQLDataAccessHelper helper=new MySQLDataAccessHelper();
         helper.Open();
         String sql=String.format("DELETE FROM xuatchieu WHERE MaXC='%d'",xc );
         int n=helper.excecuteUpdate(sql);
         helper.Close();
         return n;
    }

     
     public static ResultSet LaySoGheNgoiCuaPhong(int maxc)
    {
       try
        {
            ResultSet rs;
            MySQLDataAccessHelper dahp = new MySQLDataAccessHelper();
            dahp.Open();
            String sql = "select * from xuatchieu xc, phongchieu pc where pc.maphong = xc.maphong and xc.maxc= "+maxc;
            rs = dahp.excecuteQuery(sql);        
            return rs;
        }
        catch(Exception ex)
        {
            System.out.println(ex.getMessage());            
        }
        return null;    
    }

}
